var Session = new Class({
	initialize: function()
	{
		this.logout();
		
	}, // end function initialize
	
	logout: function()
	{
		this.status    = -1;
		this.status_de = '';
		this.username  = -1;
		this.nickname  = -1;
		this.key       = -1;
		this.id        = -1;
		this.killed    = 1;
		
	}, // end function reset
	
	isKilled: function()
	{
		return this.killed;
		
	},
	
	requiresKey: function ()
	{
		if (this.status != -1)
			return true;
		else
			return false;
			
	},
	
	check: function(u, p)
	{
		this.killed = 0;
		
		chat.getClsAjaxReq().request('login.getSeed', null, null, function (s)
		{
			var p_ = hex_md5(hex_md5(p) + s);
			loadLock = true;
			
			chat.getClsAjaxReq().request('login', ['u', 'p'], [u, p_], function (l)
			{
				loadLock = false;
				
				var lines = new Array();
				lines = l.split("\n");
				
				if (lines[0].toInt() != 1)
				{
					$('site_login_error').style.display = 'block';
					$('site_login_error').innerHTML = ((lines[0] == '-1') ? 'This account is currently logged in!' : 'Invalid username or password!');
					
					setTimeout("$('site_login_error').style.display = 'none';", 3000);
					
				} // end if
				else
				{
					this.status = 0;
					
					chat.getClsDialog().close('site_login');
					chat.getClsDialog().close('site_register');
					chat.startChatbox(lines);
					
				} // end else
				
			}, 'Checking user information.');
			
		}, 'Checking user information.');
		
	}, // end function check
	
	process: function(info)
	{
		this.username  = info[1];
		this.status    = info[2];
		this.status_de = info[3];
		this.nickname  = info[4];
		this.id        = info[5];
		this.killed    = 0;
		
	}, // end function process
	
	getStatus: function()
	{
		return this.status;
		
	}, // end function getStatus
	
	getStatusDe: function()
	{
		return this.status_de;
		
	}, // end function getStatus
	
	getNickname: function()
	{
		if (this.status != -1)
			return this.nickname;
			
	}, // end function getNickname
	
	getKey: function()
	{
		return this.key;
		
	}, // end function getKey
	
	getUsername: function()
	{
		return this.username;
		
	}, // end function getUsername
	
	setKey: function(k)
	{
		this.key = k;
		
	}, // end function setKey
	
	setStatus: function(s)
	{
		this.status = s;
	}, // end function
	
	setStatusDe: function(d)
	{
		this.status_de = d;
	} // end function
	
}); // end class Session

session_end = function()
{
	chat.getClsSession().logout();
	chat.getChat().exit();
	
	chat.getClsAjaxReq().request('kill', null, null, function(r)
	{
		if (r.toInt() != 1)
		{
			alert('Something went wrong while logging out.. You may not be able to log on your account for the next minutes.');
			
		} // end if
		
		chat.showLogin();
		
	}, 'Sending logout command.', 1);
	
} // end function

cimport_loaded('core.Session');